<template>
  <div id="print1">
    <el-row type="flex" class="" justify="center">
      <el-col :span="23" class="line">
        <i class="el-icon-time"></i>下载表格
      </el-col>
    </el-row>
    <div class="content" v-loading.fullscreen.lock="fullscreenLoading"
              element-loading-text="拼命加载中"
    element-loading-spinner="el-icon-loading"
    element-loading-background="rgba(0, 0, 0, 0.2)">
      <el-card class="box-card">
        <el-table
          :data="tableData"
          stripe
          style="width: 100%">
          <el-table-column
            prop="ticket"
            label="报名号"
            align="center">
          </el-table-column>
          <el-table-column
            prop="type"
            label="表格类型"
            align="center">
          </el-table-column>
          <el-table-column
            prop="create_time"
            label="报名时间"
            align="center">
          </el-table-column>
          <el-table-column
            prop="status"
            label="状态"
            align="center">
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            width="300px;">
            <template slot-scope="scope">
               <el-button type="primary" size="mini" @click="gotoDetail(scope.row)">下载</el-button>
               <el-button type="primary" size="mini" @click="edit_info(scope.row)" v-show="scope.row.isShow">{{scope.row.btnName}}</el-button>
                <el-button size="mini" @click="showBmback(scope.row)" v-show="scope.row.isShow1">申请驳回</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-card>
     </div>
     <!-- 驳回理由 -->
    <el-dialog title="填写理由" :visible.sync="dialogFormVisible">
        <el-form>
          <el-form-item label="申请理由" :label-width="formLabelWidth">
            <el-input v-model="reason" auto-complete="off"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="bmback">确 定</el-button>
        </div>
    </el-dialog>
  </div>
</template>

<script>
  import VDistpicker from 'v-distpicker'
  export default {

    data() {
      return {
        value:'',
        fullscreenLoading:false,
        tableData: [],
        dialogFormVisible:false,
        formLabelWidth: '85px',
        reason:''
        
      }
    },
    components: {
      VDistpicker
    },
    mounted(){
      this.getInfo();
    },
    methods: {
      getInfo(){
        var that=this;
        this.fullscreenLoading=true;
        this.axios({
          url:this.host+'/3v1t.smserver.cn/index.php/index/student.prints/getexaminfo',
          method:'post',
          headers:{
                "Content-type":"application/json"
          }
        }).then((res)=>{
          console.log(res);
          that.fullscreenLoading=false;
          var data=res.data.data;
          data.bm.forEach((item)=>{
            //显示授权
            item.isShow=true;
              if(item.allow==1){
                item.btnName="授权管理员"
              }else{
                item.btnName="取消授权"
              }
            if(item.type=="01"){
              item.type="三位一体报名表";
            }else{
              item.type="高水平运动员报名表"
            }
            if((item.isreject==1&&item.status.code==1)&&(item.step.code==1 || item.step.code==2)){
              item.isShow1=true;
            }else{
              item.isShow1=false;
            }
            item.status=item.status.name;
          })
          that.tableData=data.bm;
          if(data.cs!=null){
            data.cs.type="三位一体测试单"
            that.tableData.push(data.cs)
          }
        })
      },
      gotoDetail(mess){
        if(mess.type=="三位一体报名表"){
          window.location.href=this.host+"/3v1t.smserver.cn/index.php/index/student.Download/pdf_swyt"
        }else if(mess.type=="高水平运动员报名表"){
          window.location.href=this.host+"/3v1t.smserver.cn/index.php/index/student.Download/pdf_zxs"
        }else{
          window.location.href=this.host+"/3v1t.smserver.cn/index.php/index/student.Download/down_inid"
        }
        
      },
      edit_info(mess){
        var that=this;
        var allow=null;
        if(mess.allow==1){
          allow=2
        }else{
          allow=1
        }
        var message={
          id:mess.id,
          allow:allow
        }
        this.axios({
          url:this.host+'/3v1t.smserver.cn/index.php/index/student.prints/edit_info',
          method:'post',
          data:JSON.stringify(message),
          headers:{
                "Content-type":"application/json"
          }
        }).then((res)=>{
          console.log(res);
          if(res.data.code==1){
            that.$message({
              type:'success',
              message:''+res.data.msg
            })
            that.getInfo();
          }else{
            that.$message({
              type:'warning',
              message:''+res.data.msg
            })
          }
        })
      },
      showBmback(mess){
        this.reasonId=mess.id;
        this.dialogFormVisible=true;
      },
      bmback(){
        var that=this;
        var  message={
          id:this.reasonId,
          content:this.reason
        };
        if(this.reason==""){
          this.$message({
            type:'warning',
            message:'申请理由不能为空'
          })
        }else{
          this.axios({
            url:this.host+'/3v1t.smserver.cn/index.php/index/student.Progress/bmback',
              data:JSON.stringify(message),
            method:'post',
            headers:{
                  "Content-type":"application/json"
            }
          }).then((res)=>{
            console.log(res);
            that.fullscreenLoading=false;
            if(res.data.code==1){
              that.getInfo();
              that.dialogFormVisible=false;
                that.$message({
                  type:'success',
                  message:''+res.data.msg
                })
              } 
              else if(res.data.code==2){
                that.$message({
                      type:'warning',
                      message:''+res.data.msg
                 })
              }
          })
        }
      },
    }
  }

</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss">
  #print1 {
    //width:100%;
    //line-height:100%;
    padding: 10px;
    .line {
      border-bottom: 1px solid #ccc;
      text-align: left;
      height: 50px;
      line-height: 50px;
      padding-left: 10px;
    }
    .content {
      padding: 20px;
      text-align: center;
    }
    .download{
      float:right;
      width:130px;
      margin:0 20px;
    }
    
  }

</style>
